# -*- coding: utf-8 -*-
import scrapy
from douban.items import DoubanItem

class SpriderSpider(scrapy.Spider):
    name = 'sprider'
    allowed_domains = ['book.douban.com']
    start_urls = ['http://book.douban.com/tag/编程']

    def parse(self, response):
        book_list = response.xpath("//div[@id='subject_list']/ul[@class='subject-list']/li")
        for i_item in book_list:
            book_item = DoubanItem()
            book_item['name'] = "".join("".join(i_item.xpath("./div[@class='info']/h2").xpath("string(.)").extract()[0].split("\n")).split())
            book_item['info'] = "".join("".join(i_item.xpath("./div[@class='info']/div[@class='pub']/text()").extract_first().split("\n")).split())
            book_item['score'] = i_item.xpath("./div[@class='info']/div[2]//span[@class='rating_nums']/text()").extract_first()
            book_item['desc'] = i_item.xpath("./div[2]/p/text()").extract_first()

            yield book_item



